home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / docume1a / frmrepla (.txt) < prev    next >
Visual Basic Form  |  1999-07-18  |  8KB  |  251 lines

  1. VERSION 5.00
  2. Begin VB.Form frmReplace 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "                       Replace Text"
  5.    ClientHeight    =   2835
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4920
  9.    ClipControls    =   0   'False
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2835
  15.    ScaleWidth      =   4920
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   3  'Windows Default
  18.    WhatsThisButton =   -1  'True
  19.    WhatsThisHelp   =   -1  'True
  20.    Begin VB.CommandButton cmdClose 
  21.       Cancel          =   -1  'True
  22.       Caption         =   "&Close"
  23.       Height          =   375
  24.       Left            =   3360
  25.       TabIndex        =   10
  26.       Top             =   1920
  27.       Width           =   1215
  28.    End
  29.    Begin VB.CommandButton cmdReplaceAll 
  30.       Caption         =   "Replace &All"
  31.       Enabled         =   0   'False
  32.       Height          =   375
  33.       Left            =   3360
  34.       TabIndex        =   9
  35.       Top             =   1320
  36.       Width           =   1215
  37.    End
  38.    Begin VB.CommandButton cmdReplace 
  39.       Caption         =   "&Replace"
  40.       Enabled         =   0   'False
  41.       Height          =   375
  42.       Left            =   3360
  43.       TabIndex        =   8
  44.       Top             =   720
  45.       Width           =   1215
  46.    End
  47.    Begin VB.CommandButton cmdNext 
  48.       Caption         =   "Find &Next"
  49.       Height          =   375
  50.       Left            =   3360
  51.       TabIndex        =   7
  52.       Top             =   120
  53.       Width           =   1215
  54.    End
  55.    Begin VB.CommandButton cmdFind 
  56.       Caption         =   "&Find"
  57.       Height          =   375
  58.       Left            =   360
  59.       TabIndex        =   6
  60.       Top             =   2280
  61.       Visible         =   0   'False
  62.       Width           =   1215
  63.    End
  64.    Begin VB.CheckBox Check2 
  65.       Caption         =   "Case &Sensitive"
  66.       Height          =   375
  67.       Left            =   360
  68.       TabIndex        =   5
  69.       Top             =   1560
  70.       Width           =   1455
  71.    End
  72.    Begin VB.CheckBox Check1 
  73.       Caption         =   "&Whole Word Only"
  74.       Height          =   375
  75.       Left            =   360
  76.       TabIndex        =   4
  77.       Top             =   1200
  78.       Width           =   1575
  79.    End
  80.    Begin VB.TextBox Text2 
  81.       Height          =   285
  82.       Left            =   1440
  83.       TabIndex        =   3
  84.       Top             =   720
  85.       Width           =   1815
  86.    End
  87.    Begin VB.TextBox Text1 
  88.       Height          =   285
  89.       Left            =   1440
  90.       TabIndex        =   2
  91.       Top             =   120
  92.       Width           =   1815
  93.    End
  94.    Begin VB.Frame Frame1 
  95.       Height          =   975
  96.       Left            =   240
  97.       TabIndex        =   11
  98.       Top             =   1080
  99.       Width           =   1935
  100.    End
  101.    Begin VB.Label Label2 
  102.       AutoSize        =   -1  'True
  103.       Caption         =   "Replace With:"
  104.       BeginProperty Font 
  105.          Name            =   "MS Sans Serif"
  106.          Size            =   9.75
  107.          Charset         =   0
  108.          Weight          =   400
  109.          Underline       =   0   'False
  110.          Italic          =   0   'False
  111.          Strikethrough   =   0   'False
  112.       EndProperty
  113.       Height          =   240
  114.       Left            =   120
  115.       TabIndex        =   1
  116.       Top             =   720
  117.       Width           =   1260
  118.    End
  119.    Begin VB.Label Label1 
  120.       AutoSize        =   -1  'True
  121.       Caption         =   "Find What:"
  122.       BeginProperty Font 
  123.          Name            =   "MS Sans Serif"
  124.          Size            =   9.75
  125.          Charset         =   0
  126.          Weight          =   400
  127.          Underline       =   0   'False
  128.          Italic          =   0   'False
  129.          Strikethrough   =   0   'False
  130.       EndProperty
  131.       Height          =   240
  132.       Left            =   120
  133.       TabIndex        =   0
  134.       Top             =   120
  135.       Width           =   945
  136.    End
  137. Attribute VB_Name = "frmReplace"
  138. Attribute VB_GlobalNameSpace = False
  139. Attribute VB_Creatable = False
  140. Attribute VB_PredeclaredId = True
  141. Attribute VB_Exposed = False
  142. Dim OriginalParenthWnd As Long
  143. Dim Position As Long
  144. Private Sub cmdClose_Click()
  145. Unload Me
  146. End Sub
  147. Private Sub cmdFind_Click()
  148. Dim FindFlags As Long
  149. On Error GoTo ErrorTrap
  150. Position = 0
  151. FindFlags = Check1.Value * 2 + Check2.Value * 4
  152. Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  153. If Position >= 0 Then
  154. r = Text1.Text
  155. frmOpenDoc.SetFocus
  156. cmdReplace.Enabled = True
  157. cmdReplaceAll.Enabled = True
  158. Text2.Enabled = True
  159. Text1.Text = r
  160. MsgBox "Document has finished searching the document." & Chr(13) & Chr(13) & Chr(34) & Text1.Text & Chr(34) & " was not found!"
  161. cmdReplace.Enabled = False
  162. cmdReplaceAll.Enabled = False
  163. Text1.SetFocus
  164. Text1.SelStart = 0
  165. Text1.SelLength = Len(Text1.Text)
  166. End If
  167. Exit Sub
  168. ErrorTrap:
  169. Call ErrorTrap
  170. End Sub
  171. Private Sub cmdNext_Click()
  172. Dim FindFlags As Long
  173. On Error GoTo ErrorTrap
  174. FindFlags = Check1.Value * 2 + Check2.Value * 4
  175. Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  176. If Position > 0 Then
  177. p = Text1.Text
  178. frmOpenDoc.SetFocus
  179. cmdReplace.Enabled = True
  180. cmdReplaceAll.Enabled = True
  181. Text2.Enabled = True
  182. Text1.Text = p
  183. MsgBox "Document has finished searching the document." & Chr(13) & Chr(13) & Chr(34) & Text1.Text & Chr(34) & " was not found!"
  184. cmdReplace.Enabled = False
  185. cmdReplaceAll.Enabled = False
  186. Text1.SetFocus
  187. Text1.SelStart = 0
  188. Text1.SelLength = Len(Text1.Text)
  189. End If
  190. Exit Sub
  191. ErrorTrap:
  192. Call ErrorTrap
  193. End Sub
  194. Private Sub cmdReplace_Click()
  195. Dim FindFlags As Integer
  196. On Error GoTo ErrorTrap
  197. frmOpenDoc.RichTextBox1.SelText = Text2.Text
  198. FindFlags = Check1.Value * 2 + Check2.Value * 4
  199. Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  200. If Position > 0 Then
  201. frmFind.Hide
  202. frmOpenDoc.SetFocus
  203. boolsave = True
  204. SaveEnabled
  205. MsgBox "Document has finished replacing " & Chr(34) & Text1.Text & Chr(34) & " with " & Chr(34) & Text2.Text & Chr(34)
  206. cmdReplace.Enabled = False
  207. cmdReplaceAll.Enabled = False
  208. Text1.SetFocus
  209. End If
  210. Exit Sub
  211. ErrorTrap:
  212. Call ErrorTrap
  213. End Sub
  214. Private Sub cmdReplaceAll_Click()
  215. On Error GoTo ErrorTrap
  216. FindFlags = Check1.Value * 2 + Check2.Value * 4
  217. frmOpenDoc.RichTextBox1.SelText = Text2.Text
  218. Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  219. While Position > 0
  220. Screen.MousePointer = 11
  221. MDIForm1.StatusBar1.Panels(1).Text = "Replacing text, please wait..."
  222. frmOpenDoc.RichTextBox1.SelText = Text2.Text
  223. Position = frmOpenDoc.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  224. Screen.MousePointer = 0
  225. cmdReplace.Enabled = False
  226. cmdReplaceAll.Enabled = False
  227. MsgBox "Document has finished replacing " & Chr(34) & Text1.Text & Chr(34) & " with " & Chr(34) & Text2.Text & Chr(34)
  228. boolsave = True
  229. Text1.SetFocus
  230. SaveEnabled
  231. MDIForm1.StatusBar1.Panels(1).Text = MDIForm1.CommonDialog1.FileName
  232. Exit Sub
  233. ErrorTrap:
  234. Call ErrorTrap
  235. End Sub
  236. Private Sub Form_Load()
  237. frmOpenDochwnd = SetWindowLong(Me.hwnd, GWW_HWNDPARENT, frmOpenDoc.hwnd)
  238. Width = 0.4 * Screen.Width
  239. Height = 0.32 * Screen.Height
  240. Left = (Screen.Width - Width) / 2
  241. Top = (Screen.Height - Height) / 2
  242. End Sub
  243. Private Sub Form_Unload(Cancel As Integer)
  244. Dim r As Long
  245. r = SetWindowLong(Me.hwnd, GWW_HWNDPARENT, OriginalParenthWnd)
  246. End Sub
  247. Private Sub Text2_Change()
  248. cmdReplace.Enabled = (Len(Text2.Text) > 0)
  249. cmdReplaceAll.Enabled = (Len(Text2.Text) > 0)
  250. End Sub
  251.